import logging

import requests

import app


class EmpApi:
    def __init__(self, token):
        self.header_dict = {"Authorization": token}
        self.url = app.Base_HOST + "/api/sys/user"
        self.url_id = app.Base_HOST + "/api/sys/user/{}"

    # 新增员工
    def add_emp(self, json_dict):
        res_add = requests.post(url=self.url, headers=self.header_dict, json=json_dict)
        logging.info("新增员工接口返回的数据:{}".format(res_add.json()))
        return res_add

    # 查询员工
    def query_emp(self, id):
        res = requests.get(url=self.url_id.format(id), headers=self.header_dict)
        logging.info("查询员工接口返回的数据:{}".format(res.json()))
        return res

    # 修改员工
    def update_emp(self, id, json_dict):
        res = requests.put(url=self.url_id.format(id), headers=self.header_dict, json=json_dict)
        logging.info("修改员工接口返回的数据:{}".format(res.json()))
        return res

    # 删除员工
    def delete_emp(self, id):
        res = requests.delete(url=self.url_id.format(id), headers=self.header_dict)
        logging.info("删除员工接口返回的数据:{}".format(res.json()))
        return res
